<?php

/**
 * 号码区段
 *
 * The followings are the available columns in table 'mobile':
 * @property integer $id
 * @property string $mobile
 * @property string $area
 * @property string $type
 * @property string $areacode
 * @property string $postcode
 * @property integer $times
 * @property integer $postion
 */
class Mobile extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @param string $className active record class name.
	 * @return Mobile the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'mobile';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('times, postion', 'numerical', 'integerOnly'=>true),
			array('mobile', 'length', 'max'=>7),
			array('mobile', 'unique'),
			array('area, type', 'length', 'max'=>20),
			array('areacode', 'length', 'max'=>5),
			array('postcode', 'length', 'max'=>6),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('id, mobile, area, type, areacode, postcode, times, postion', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'ID',
			'mobile' => '号码段',
			'area' => '地区',
			'type' => '类型',
			'areacode' => '区号',
			'postcode' => '邮编',
			'times' => '扫描次数',
			'postion' => '扫描位置',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('id',$this->id);
		$criteria->compare('mobile',$this->mobile,true);
		$criteria->compare('area',$this->area,true);
		$criteria->compare('type',$this->type,true);
		$criteria->compare('areacode',$this->areacode,true);
		$criteria->compare('postcode',$this->postcode,true);
		$criteria->compare('times',$this->times);
		$criteria->compare('postion',$this->postion);
		$criteria->order=' times , postion desc ';
		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,'pagination'=>array('pageSize'=>20)
		));
	}
}